package com.sl.plat.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sl.common.ResponseData;
import com.sl.water.entity.PlanOrg;
import com.sl.water.entity.PlanStatic;
import com.sl.water.service.PlanOrgService;
import com.sl.water.vo.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:预案组织管理接口
 * @author: duan
 * @time: 2025-06-27 14:46
 */

@RestController
@RequestMapping("/plat/plan/org")
@CrossOrigin
@RequiredArgsConstructor
@Slf4j
@Tag(name = "预案-组织管理", description = "预案组织管理接口")
public class PlanOrgController {

    private final PlanOrgService planOrgService;

    @PostMapping
    @Operation(summary = "新增")
    public ResponseData save(@RequestBody PlanOrgIVO planOrgVO) {
        PlanOrg planOrg = BaseVO.convert(planOrgVO, PlanOrg.class);
        planOrgService.save(planOrg);
        return ResponseData.success(planOrg.getId());
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除")
    public ResponseData removeById(
            @Parameter(
                    description = "主键",
                    required = true,
                    example = "1"
            )
            @PathVariable long id) {
        planOrgService.removeById(id);
        return ResponseData.success("删除成功");
    }

    @PutMapping("/{id}")
    @Operation(summary = "修改")
    public ResponseData updateById(
            @Parameter(
                    description = "主键",
                    required = true,
                    example = "1"
            )
            @PathVariable long id, @RequestBody PlanOrgIVO planOrgVO) {
        PlanOrg planOrg = BaseVO.convert(planOrgVO, PlanOrg.class);
        planOrg.setId(id);
        planOrgService.updateById(planOrg);
        return ResponseData.success("修改成功");
    }

    @GetMapping("/{id}")
    @Operation(summary = "查询")
    public ResponseData<PlanOrg> get(
            @Parameter(
                    description = "主键",
                    required = true,
                    example = "1"
            )
            @PathVariable long id) {
        return ResponseData.success(planOrgService.getById(id));
    }

    @GetMapping("/pageList")
    @Operation(summary = "分页列表查询")
    public ResponseData<Page<PlanOrg>> pageList(
            @Parameter(
                    description = "页码",
                    example = "1", required = true
            )
            @RequestParam(defaultValue = "1") int page,
            @Parameter(
                    description = "分页数量",
                    example = "10", required = true
            )
            @RequestParam(defaultValue = "10") int size) {
        Page<PlanOrg> planStaticPage = planOrgService.pageList(page, size);
        return ResponseData.success(planStaticPage);
    }
}
